package com.viettel.pon.Tabs;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

import org.apache.log4j.Logger;
import org.json.JSONObject;

import com.viettel.pon.R;
import com.viettel.pon.adapter.ListPolesAdapter;
import com.viettel.pon.common.Constant;
import com.viettel.pon.common.DataBaseHelper;
import com.viettel.pon.common.DialogCommon;
import com.viettel.pon.common.GPSTracker;
import com.viettel.pon.common.GlobalClass;
import com.viettel.pon.common.Validation;
import com.viettel.pon.form.InfomationForm;
import com.viettel.pon.main.MainActivity;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.app.ActionBar.LayoutParams;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
 
public class SearchActivity extends Fragment {
	private Logger mLog;
	String VNCHAR = "^([a-zA-Z0-9\\_/]+)$";
	String SPECIALCHAR = "/^[^\\`\\~\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\+\\=\\<\\>\\?\\-\\/]*$/";
	String DOUBLECHAR = "^[0-9]{1,9}\\.?[0-9]{1,9}$";
	String INTCHAR = "^[0-9]{1,9}$";
	private ListView lvListCol;
	private TextView txtListCol;
	private ImageButton ibtSearch;
	private EditText edtSearchValue;
	private TextView txtKinhdo;
	private TextView txtVido;
	private TextView txtMacotdien;
	private TextView txtLoaicotdien;
	private TextView txtChusohuu;
	private TextView txtSohodan;
	private TextView txtGhichu;
	private TextView txtNewOrOld;
	
	private EditText edtKinhdo;
	private EditText edtVido;
	private EditText edtMacotdien;
	private EditText edtSohodan;
	private EditText edtGhichu;
	private Button btnLaytoado;
	private Button btnSave;
	private Button btnDeleteCol;
	
	private RadioGroup rdoLoaicotdien;
	private RadioGroup rdoChusohuu;
	private CheckBox chkNewOrOld;
	private RadioButton rbLoaicotdien;
	private RadioButton rbChusohuu;
	
	private Context _context;
	DataBaseHelper db;
	private ProgressDialog pDialog;
	private ArrayList<InfomationForm>  lstCol=null;
	 View rootView;
	 private GlobalClass _glb;
	 int width;
		GPSTracker gps;
		DialogCommon _dlg;
	 PopupWindow PopupWindowPole;
	 View popupViewPoles;
	private Button btnExit;
	private RadioButton rdoVuongdon;
	private RadioButton rdoVuongdoi;
	private RadioButton rdoTrondon;
	private RadioButton rdoTrondoi;
	private RadioButton rdoCotthep;
	private RadioButton rdoCotgo;
	private RadioButton rdoViettel;
	private RadioButton rdoVNPT;
	private RadioButton rdoDienluc;
	private RadioButton rdoXa;
	
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
    	mLog = Logger.getLogger(SearchActivity.class);
        rootView = inflater.inflate(R.layout.activity_list_col, container, false);
        _context=getActivity().getApplicationContext();
        _glb=(GlobalClass)_context.getApplicationContext();
        DisplayMetrics displaymetrics = new DisplayMetrics();
        _dlg=new DialogCommon(getActivity());
		getActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
		 width = displaymetrics.widthPixels/10;  
		TableRow.LayoutParams params1 = new TableRow.LayoutParams(width*10,
				TableRow.LayoutParams.FILL_PARENT);
		
		 String myTag = getTag();
		 ((MainActivity)getActivity()).setTabSearch(myTag);
		 
    	db = new DataBaseHelper(_context);
        lvListCol=(ListView) rootView.findViewById(R.id.lvListCol);
        txtListCol=(TextView) rootView.findViewById(R.id.txtListCol);
//        btnSynData=(Button) rootView.findViewById(R.id.btnSynData);
        ibtSearch=(ImageButton) rootView.findViewById(R.id.ibtSearch);
        edtSearchValue=(EditText) rootView.findViewById(R.id.edtSearchValue);
        		
        lvListCol.setLayoutParams(params1);
        txtListCol.setLayoutParams(params1);
//        btnSynData.setLayoutParams(new TableRow.LayoutParams(width*4,
//				TableRow.LayoutParams.WRAP_CONTENT));
        edtSearchValue.setLayoutParams(new TableRow.LayoutParams(width*7,
				TableRow.LayoutParams.WRAP_CONTENT));
//        ibtSearch.setLayoutParams(new TableRow.LayoutParams(width*3,
//				TableRow.LayoutParams.WRAP_CONTENT));
        
        getActivity().getWindow().setSoftInputMode(
        	      WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        lstCol=new ArrayList<InfomationForm>();
        	lstCol=db.getAllCol();
        	ArrayAdapter<InfomationForm> adapter = new ListPolesAdapter(_context, lstCol, width);
         	adapter.notifyDataSetChanged();
        	lvListCol.setAdapter(adapter);
        	
        	lvListCol.setOnItemClickListener(new OnItemClickListener() {

				@Override
				public void onItemClick(AdapterView<?> arg0, View arg1,
						int arg2, long arg3) {
					// TODO Auto-generated method stub
					InfomationForm item=(InfomationForm) arg0.getItemAtPosition(arg2);
	            	Log.e("id", String.valueOf(item.getId()));
	            	mLog.info("Listview.setOnItemClick");
					_glb.setColId(item.getId());
					Log.e("ColCode:     ", String.valueOf(item.getId()));
					showPopupPoles();
					setData();
				}
			});
        
        ibtSearch.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(!edtSearchValue.getText().toString().trim().isEmpty()){
					lstCol=new ArrayList<InfomationForm>();
				  lstCol=db.getColByCode(edtSearchValue.getText().toString().trim());
				   ArrayAdapter<InfomationForm> adapter = new ListPolesAdapter(_context, lstCol, width);
				   adapter.notifyDataSetChanged();
			        lvListCol.setAdapter(adapter);
			    	mLog.info("Search Poles");
				}
				 
			}
		});
        return rootView;
    }
    
  
    @Override
	public void onResume() {
		super.onResume();
		edtSearchValue.setText("");
		lstCol=new ArrayList<InfomationForm>();
		lstCol = db.getAllCol();
		if (lstCol.size() > 0) {
			ArrayAdapter<InfomationForm> adapter = new ListPolesAdapter(_context, lstCol, width);
			adapter.notifyDataSetChanged();
			lvListCol.setAdapter(adapter);
		}
	}
    
   /*
    * reload list poles
    */

	public void reloadListView(){
		edtSearchValue.setText("");
		lstCol=new ArrayList<InfomationForm>();
		lstCol = db.getAllCol();
		if (lstCol.size() > 0) {
			ArrayAdapter<InfomationForm> adapter =  new ListPolesAdapter(_context, lstCol, width);
			adapter.notifyDataSetChanged();
			lvListCol.setAdapter(adapter);
		}
	}
	
	/*
	 * cap nhat cot dien
	 */
	
	private void showPopupPoles() {
		LayoutInflater layoutInflater = (LayoutInflater) getActivity()
				.getBaseContext().getSystemService(
						Context.LAYOUT_INFLATER_SERVICE);
		mLog.info("Show popup edit Poles");
		popupViewPoles = layoutInflater.inflate(R.layout.activity_viewdetailcol,
				null);
		
		DisplayMetrics displaymetrics = new DisplayMetrics();
		getActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
		int width = displaymetrics.widthPixels/10;  
		TableRow.LayoutParams params1 = new TableRow.LayoutParams(width*4,
				TableRow.LayoutParams.WRAP_CONTENT);
		
		txtKinhdo=(TextView) popupViewPoles.findViewById(R.id.txtKinhdo);
		txtVido=(TextView) popupViewPoles.findViewById(R.id.txtVido);
		txtMacotdien=(TextView) popupViewPoles.findViewById(R.id.txtMacotdien);
		txtLoaicotdien=(TextView) popupViewPoles.findViewById(R.id.txtLoaicotdien);
		txtChusohuu=(TextView) popupViewPoles.findViewById(R.id.txtChusohuu);
		txtSohodan=(TextView) popupViewPoles.findViewById(R.id.txtSohodan);
		txtGhichu=(TextView) popupViewPoles.findViewById(R.id.txtGhichu);
		txtNewOrOld=(TextView) popupViewPoles.findViewById(R.id.txtNewOrOld);

		edtKinhdo=(EditText) popupViewPoles.findViewById(R.id.edtKinhdo);
		edtVido=(EditText) popupViewPoles.findViewById(R.id.edtVido);
		edtMacotdien=(EditText) popupViewPoles.findViewById(R.id.edtMacotdien);
		edtSohodan=(EditText) popupViewPoles.findViewById(R.id.edtSohodan);
		edtGhichu=(EditText) popupViewPoles.findViewById(R.id.edtGhichu);
		
		btnLaytoado=(Button) popupViewPoles.findViewById(R.id.btnLaytoado);
		btnSave=(Button) popupViewPoles.findViewById(R.id.btnSave);
		btnExit = (Button) popupViewPoles.findViewById(R.id.btnExit);
		btnDeleteCol=(Button) popupViewPoles.findViewById(R.id.btnDeleteCol);
		
		rdoLoaicotdien =(RadioGroup) popupViewPoles.findViewById(R.id.rdoLoaicotdien);
		rdoChusohuu =(RadioGroup) popupViewPoles.findViewById(R.id.rdoChusohuu);
		chkNewOrOld =(CheckBox) popupViewPoles.findViewById(R.id.chkNewOrOld);
		rdoVuongdon = (RadioButton) popupViewPoles
				.findViewById(R.id.rdoVuongdon);
		rdoVuongdoi = (RadioButton) popupViewPoles
				.findViewById(R.id.rdoVuongdoi);
		rdoTrondon = (RadioButton) popupViewPoles
				.findViewById(R.id.rdoTrondon);
		rdoTrondoi = (RadioButton) popupViewPoles
				.findViewById(R.id.rdoTrondoi);
		rdoCotthep = (RadioButton) popupViewPoles
				.findViewById(R.id.rdoCotthep);
		rdoCotgo = (RadioButton) popupViewPoles
				.findViewById(R.id.rdoCotgo);
		rdoViettel = (RadioButton) popupViewPoles
				.findViewById(R.id.rdoViettel);
		rdoVNPT = (RadioButton) popupViewPoles
				.findViewById(R.id.rdoVNPT);
		rdoDienluc = (RadioButton) popupViewPoles
				.findViewById(R.id.rdoDienluc);
		rdoXa = (RadioButton) popupViewPoles
				.findViewById(R.id.rdoXa);
		txtKinhdo.setLayoutParams(new TableRow.LayoutParams(width*2,
				TableRow.LayoutParams.WRAP_CONTENT));
		txtVido.setLayoutParams(new TableRow.LayoutParams(width*2,
				TableRow.LayoutParams.WRAP_CONTENT));
		txtMacotdien.setLayoutParams(new TableRow.LayoutParams(width*2,
				TableRow.LayoutParams.WRAP_CONTENT));
		txtLoaicotdien.setLayoutParams(new TableRow.LayoutParams(width*2,
				TableRow.LayoutParams.WRAP_CONTENT));
		txtChusohuu.setLayoutParams(new TableRow.LayoutParams(width*2,
				TableRow.LayoutParams.WRAP_CONTENT));
		txtSohodan.setLayoutParams(new TableRow.LayoutParams(width*2,
				TableRow.LayoutParams.WRAP_CONTENT));
		txtNewOrOld.setLayoutParams(new TableRow.LayoutParams(width*2,
				TableRow.LayoutParams.WRAP_CONTENT));
		txtGhichu.setLayoutParams(new TableRow.LayoutParams(width*2,
				TableRow.LayoutParams.WRAP_CONTENT));

		edtKinhdo.setLayoutParams(params1);
		edtVido.setLayoutParams(params1);
		edtMacotdien.setLayoutParams(params1);
		edtSohodan.setLayoutParams(params1);
		edtGhichu.setLayoutParams(params1);
		
		btnLaytoado.setLayoutParams(new TableRow.LayoutParams(width*2,
				TableRow.LayoutParams.WRAP_CONTENT));
		rdoLoaicotdien.setLayoutParams(params1);
		rdoChusohuu.setLayoutParams(params1);
		
		PopupWindowPole = new PopupWindow(popupViewPoles,
				LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		PopupWindowPole.showAtLocation(popupViewPoles, Gravity.CENTER, 0, 0);
		PopupWindowPole.setFocusable(true);
		PopupWindowPole.update();
		
		btnLaytoado.setOnClickListener(new OnClickListener() {
	   	     
	   		@Override
	   		public void onClick(View v) {
	   		  // create class object
	            gps = new GPSTracker(_context);
	            mLog.info("Get position Edit Poles");
	            // check if GPS enabled     
	            if(gps.canGetLocation()){
	                double latitude = gps.getLatitude();
	                double longitude = gps.getLongitude();
	               
	                edtKinhdo.setText(String.valueOf(latitude));
	                edtVido.setText(String.valueOf(longitude));
	                mLog.info("Get position Success");
	                
	            }else{
	                // can't get location
	                // GPS or Network is not enabled
	                // Ask user to enable GPS/network in settings
	                gps.showSettingsAlert();
	                mLog.info("Get position Fail");
	                mLog.info("GPS or Network is not enabled");
	            }
	             
	   		}
	    
	   	});
		
		
		
		btnDeleteCol.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				 mLog.info("Delete Poles");
				dlgConfirmDeleteCol().show();
				
			}
		});
		
		btnSave.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				 mLog.info("Update Poles");
				dlgConfirmUpdateCol().show();
			}
		});
		
		btnExit.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				PopupWindowPole.dismiss();
			}
		});
			
	}
	
	/*
	 * set data for update
	 */
	  private void setData(){
			 mLog.info("Set data preUpdate Poles");
	    	int colId=_glb.getColId();
	    	List<InfomationForm> lst=new ArrayList<InfomationForm>();
	    	lst=db.getColById(colId);
	    	if(lst.size()>0){
	    		edtGhichu.setText(lst.get(0).getNote());
	    		edtKinhdo.setText(lst.get(0).getLatitude());
	    		edtVido.setText(lst.get(0).getLongtitude());
	    		edtMacotdien.setText(lst.get(0).getCol_code());
	    		if(Integer.toString(lst.get(0).getNum_people()).compareToIgnoreCase("-1")==0){
	    			edtSohodan.setText("");
	    		}else{
	    			edtSohodan.setText(Integer.toString(lst.get(0).getNum_people()));	
	    		}
	    		if(lst.get(0).getCol_type()==Constant.POLES_TYPE.VuongDon){
	    			rdoLoaicotdien.check(R.id.rdoVuongdon);
		        }else if(lst.get(0).getCol_type()==Constant.POLES_TYPE.VuongDoi){
		        	rdoLoaicotdien.check(R.id.rdoVuongdoi);
		        }else if(lst.get(0).getCol_type()==Constant.POLES_TYPE.TronDon){
		        	rdoLoaicotdien.check(R.id.rdoTrondon);
		        }else if(lst.get(0).getCol_type()==Constant.POLES_TYPE.TronDoi){
		        	rdoLoaicotdien.check(R.id.rdoTrondoi);
		        }else if(lst.get(0).getCol_type()==Constant.POLES_TYPE.CotThep){
		        	rdoLoaicotdien.check(R.id.rdoCotthep);
		        }else if(lst.get(0).getCol_type()==Constant.POLES_TYPE.CotGo){
		        	rdoLoaicotdien.check(R.id.rdoCotgo);
		        }
	    		if(lst.get(0).getOwner()==Constant.POLES_OWNER.Viettel){
	    			rdoChusohuu.check(R.id.rdoViettel);
		        }else if(lst.get(0).getOwner()==Constant.POLES_OWNER.VNPT){
		        	rdoChusohuu.check(R.id.rdoVNPT);
		        }else if(lst.get(0).getOwner()==Constant.POLES_OWNER.DienLuc){
		        	rdoChusohuu.check(R.id.rdoDienluc);
		        }else if(lst.get(0).getOwner()==Constant.POLES_OWNER.Xa){
		        	rdoChusohuu.check(R.id.rdoXa);
		        }
	    		
	    		if(lst.get(0).getNeworold()==Constant.NEW_OR_OLD.New){
	    			chkNewOrOld.setChecked(true);
		        }else if(lst.get(0).getNeworold()==Constant.NEW_OR_OLD.Old){
		        	chkNewOrOld.setChecked(false);
		        }
	    		
	    	}
	    }
	  /*
	   * Cac dialog thong bao
	   */
	  
	  public AlertDialog dlgConfirmDeleteCol() {
			AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
			builder.setTitle(Constant.MESSAGE_STR.NOTIFY);
			builder.setMessage(Constant.MESSAGE_STR.CONFIRM_DELETE_POLES);
			builder.setCancelable(false);
			builder.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					Log.e("delete colcode:   ", String.valueOf(_glb.getColId()));
					if(db.onDeleteByColId(_glb.getColId())==1){
						 mLog.info("Delete Poles Success");
						createDialogErrorNotReturn(Constant.MESSAGE_STR.DELETE_SUCCESS).show();
					
					}else{
						 mLog.info("Delete Poles Fail");
						createDialogErrorNotReturn(Constant.MESSAGE_STR.DELETE_FAIL).show();
					}
					
				}
			});
			builder.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					 mLog.info("Delete Poles Cancel");
				}
			});
			AlertDialog dialog = builder.create();
			return dialog;
		}
	  
	  public AlertDialog dlgConfirmUpdateCol() {
			AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
			builder.setTitle(Constant.MESSAGE_STR.NOTIFY);
			builder.setMessage(Constant.MESSAGE_STR.CONFIRM_UPDATE_POLES);
			builder.setCancelable(false);
			builder.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					Log.e("update colcode:   ", String.valueOf(_glb.getColId()));
					 mLog.info("Update Poles Start");
	 			int selectedColTypeId = rdoLoaicotdien.getCheckedRadioButtonId();
	 			int selectedOwnerId = rdoChusohuu.getCheckedRadioButtonId();
 		        rbLoaicotdien = (RadioButton) popupViewPoles.findViewById(selectedColTypeId);
 		        rbChusohuu = (RadioButton) popupViewPoles.findViewById(selectedOwnerId);
	 		   
	 		 if(validatePoles()){
	 		        InfomationForm info=new InfomationForm();
	 		        info.setId(_glb.getColId());
	 		        info.setCol_code(edtMacotdien.getText().toString().trim());
	 		        info.setLatitude(edtKinhdo.getText().toString().trim());
	 		        info.setLongtitude(edtVido.getText().toString().trim());
	 		        info.setNote(edtGhichu.getText().toString().trim());
	 		       
	 		        if (edtSohodan.getText().toString().trim().length() > 0) {
						info.setNum_people(Integer.parseInt(edtSohodan.getText()
								.toString().trim()));
					} else {
						info.setNum_people(0);
					}
	 		       
	 		       	// Loai cot
					if(rdoVuongdon.isChecked()){
						info.setCol_type(Constant.POLES_TYPE.VuongDon);
					}
					if(rdoVuongdoi.isChecked()){
						info.setCol_type(Constant.POLES_TYPE.VuongDoi);
					}
					if(rdoTrondon.isChecked()){
						info.setCol_type(Constant.POLES_TYPE.TronDon);
					}
					if(rdoTrondoi.isChecked()){
						info.setCol_type(Constant.POLES_TYPE.TronDoi);
					}
					if(rdoCotthep.isChecked()){
						info.setCol_type(Constant.POLES_TYPE.CotThep);
					}
					if(rdoCotgo.isChecked()){
						info.setCol_type(Constant.POLES_TYPE.CotGo);
					}
					
					// Chu so huu
					if(rdoViettel.isChecked()){
						info.setOwner(Constant.POLES_OWNER.Viettel);
					}
					if(rdoVNPT.isChecked()){
						info.setOwner(Constant.POLES_OWNER.VNPT);
					}
					if(rdoDienluc.isChecked()){
						info.setOwner(Constant.POLES_OWNER.DienLuc);
					}
					if(rdoXa.isChecked()){
						info.setOwner(Constant.POLES_OWNER.Xa);
					}
	 		    if (chkNewOrOld.isChecked()) {
					info.setNeworold(Constant.NEW_OR_OLD.New);
				} else {
					info.setNeworold(Constant.NEW_OR_OLD.Old);
				}
 		        if(db.updateInfoCol(info)==0){
 		        	 mLog.info("Update Poles Success");
 		        	createDialogErrorNotReturn(Constant.MESSAGE_STR.UPDATE_SUCCESS).show();
 		        }else{
 		        	 mLog.info("Update Poles Fail");
 		        	createDialogErrorNotReturn(Constant.MESSAGE_STR.UPDATE_FAIL).show();
 		        }
	 		 }
				}
			});
			builder.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					 mLog.info("Update Poles Cancel");
				}
			});
			AlertDialog dialog = builder.create();
			return dialog;
		}
	  
	  private boolean validatePoles() {
			if (edtMacotdien.getText().toString().trim().length() < 1) {
				createDialogValidate(Constant.MESSAGE_STR.POLES_CODE_REQUIED).show();
				return false;
			}
			if (edtVido.getText().toString().trim().length() == 0) {
				createDialogValidate(Constant.MESSAGE_STR.LAT_ISREQUIED)
 				.show();
 	 		   	return false;
 	 		   	}
			if (edtKinhdo.getText().toString().trim().length() == 0) {
				createDialogValidate(Constant.MESSAGE_STR.LONG_ISREQUIED)
				.show();
	 		   	return false;
	 		   	}
			
//			  if(!Pattern.matches(DOUBLECHAR,edtKinhdo.getText().toString().trim())){
//				  createDialogValidate(Constant.MESSAGE_STR.LONG_ISDOUBLE)
//					.show();
//		 		   	return false;
//				}
//	 		  if(!Pattern.matches(DOUBLECHAR,edtVido.getText().toString().trim())){
//	 			 createDialogValidate(Constant.MESSAGE_STR.LAT_ISDOUBLE)
//					.show();
//		 		   	return false;
//				}
//				if(!Pattern.matches(VNCHAR,edtMacotdien.getText().toString().trim())){
//					createDialogValidate(Constant.MESSAGE_STR.POLES_CODE_NOTSPECIAL)
//	 				.show();
//	 	 		   	return false;
//				}
				if(edtSohodan.getText().toString().trim().length()>0 && !Pattern.matches(INTCHAR,edtSohodan.getText().toString().trim())){
					createDialogValidate(Constant.MESSAGE_STR.NUM_HOUSE_ISINT)
	 				.show();
	 	 		   	return false;
				}
			if (edtSohodan.getText().toString().trim().length() < 1) {
				createDialogValidate(Constant.MESSAGE_STR.NUM_HOUSE_REQUIED).show();
				return false;
			}

			return true;
		}

	  
	    public AlertDialog createDialogErrorNotReturn(String msg) {
			AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
			builder.setTitle(Constant.MESSAGE_STR.NOTIFY);
			builder.setMessage(msg);
			builder.setCancelable(false);
		
			builder.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					reloadListView();
				PopupWindowPole.dismiss();
				}
			});
			AlertDialog dialog = builder.create();
			return dialog;
		}
	    
	    public AlertDialog createDialogValidate(String msg) {
			AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
			builder.setTitle(Constant.MESSAGE_STR.NOTIFY);
			builder.setMessage(msg);
			builder.setCancelable(false);

			builder.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {

				}
			});
			AlertDialog dialog = builder.create();
			return dialog;
		}
	    
}